<?php
class Jnd_View_Helper_FormSelectjnd extends Zend_View_Helper_FormSelect
{
    protected $_attribsJnd = array();

    public function formSelectjnd( $name, $value = null, $attribs = null, $options = null, $listsep = "<br />\n" )
    {
        $this->_attribsJnd = $attribs;
        return parent::formSelect($name, $value, $attribs, $options, $listsep);
    }

    /**
     * Builds the actual <option> tag
     *
     * @param string $value
     *            Options Value
     * @param string $label
     *            Options Label
     * @param array $selected
     *            The option value(s) to mark as 'selected'
     * @param array|bool $disable
     *            Whether the select is disabled, or individual options are
     * @return string Option Tag XHTML
     */
    protected function _build( $value, $label, $selected, $disable )
    {
        $attribs = $this->_attribsJnd;
        if (isset($attribs['chercherValeurDansLesCles']) && $attribs['chercherValeurDansLesCles'] === true) {
            $chercherValeurDansLesCles = true;
        } else {
            $chercherValeurDansLesCles = false;
        }
        
        if (is_bool($disable)) {
            $disable = array();
        }
        
        $opt = '<option' . ' value="' . $this->view->escape($value) . '"' . ' label="' . $this->view->escape($label) . '"';
        
        // selected?
        if ($chercherValeurDansLesCles) {
            if (array_key_exists((string) $value, $selected)) {
                $opt .= ' selected="selected"';
            }
        } else {
            if (in_array((string) $value, $selected)) {
                $opt .= ' selected="selected"';
            }
        }
        
        // disabled?
        if (in_array($value, $disable)) {
            $opt .= ' disabled="disabled"';
        }
        
        $opt .= '>' . $this->view->escape($label) . "</option>";
        
        return $opt;
    }
}

